<template>
  <div>
<!--    <div v-for="val in list" :key="val.id">
      <van-divider />
      <van-cell-group inset>
        <van-cell :title="'留言'+val.id">
          &lt;!&ndash; 使用 right-icon 插槽来自定义右侧图标 &ndash;&gt;
          <template #right-icon>
            <van-icon name="clear" class="van-icon-clear" size="30" @click="deleteCard(val.id,val.desc)"/>
          </template>
        </van-cell>
        <van-cell title="" :label="val.desc" >

        </van-cell>


      </van-cell-group>

    </div>-->
<!--    <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
    >-->
      <van-cell-group inset>
        <van-cell :title="'留言'+id">
          <template #right-icon>
            <van-icon name="close" size="30" @click="deleteCard(id,desc)"/>

          </template>
        </van-cell>
        <van-cell title="" :label="desc" >
        </van-cell>
      </van-cell-group>

    <van-card
        num="2"
        price="2.00"
        desc="描述信息"
        title="商品标题"
    />
<!--    </van-list>-->

  </div>
</template>

<script>
import {Dialog} from "vant";
import {deleteOneSay} from "../utils/api";
import {Bus} from "../bus";

export default {
  name: "Card",
  props:{
    id: Number,
    desc: String
  },
  data(){
    return {
      list:[
          // {id:1,desc:'中国1'},
          // {id:2,desc:'中国2'},
          // {id:3,desc:'中国3'},
          // {id:4,desc:'中国4'},
          // {id:5,desc:'中国5'},
      ],
      loading: false,
      finished: false,
      name: this.$route.params.name
    }
  },
  methods:{

    async deleteCard(id,desc){



      /*--------------*/
      console.log(id,desc)
      const userId = this.$store.getters.getUserInfo.id
      const {data:res} = await deleteOneSay(this.name,desc,userId)

      console.log(res)

      Bus.$emit('delete-card',id,desc)



    },
    onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      setTimeout(() => {
        // 加载状态结束
        this.loading = false;
        // 数据全部加载完成
        if (this.list.length >= 0) {
          this.finished = true;
        }
      }, 10);
    },
    success(){
      Dialog.alert({
        title: '消息',
        message: '删除成功',
        theme: 'round-button',
      }).then(() => {
        // on close
      });
    },


  },
  created() {
    console.log('-------')
    console.log(this.$route)
  }
}
</script>

<style scoped>

</style>